package com.company;

public class lglr {
    private  double x1;
    private  double x2;
    private  double x3;
    public void star(){
        System.out.printf("开始牛顿差值计算\n");
        System.out.printf("函数值为f(x)=Math.sqrt(x)\n三个点(100,10),(121,11),(144,12);\n求x=115的值：\n");
        double [][]arr=new double[3][3];
        double []lis={100,121,144};
        for (int i=1;i<=2;i++){
            for(int j=0;j<i;j++){
                if(j>0){
                    arr[i][j]=(arr[i][j-1]-arr[i-1][j-1])/(lis[i]-lis[0]);///求j+1阶差商
                }else if(j==0) {
                    arr[i][j]=(Math.sqrt(lis[i])-Math.sqrt(lis[i-1]))/(lis[i]-lis[i-1]);///求一阶差商
                }
            }
        }
        System.out.println("差商表如下所示：");
        for (int i=0;i<=2;i++){
            for (int j=0;j<=2;j++){
                System.out.print(arr[i][j]+"||");
            }
            System.out.println("\n");
        }

        double a=0;

            a+=10+arr[1][0]*(115-100);
          a+=arr[2][1]*(115-100)*(115-121);
        System.out.println("则带入牛顿插值公式："+a);


    }
}
